<h2>修改文件</h2>
<div id="manage-file-file-modify"
     data-topple="hsForm"
     data-save-url="common/fold/update.act"
     data-load-url="common/fold/search.act?path=${path}&amp;type=file&amp;ab=_">
    <form action="" method="POST">
        <input type="hidden" name="path" data-fn/>
        <input type="hidden" name="type" value="file"/>
        <div class="form-group row" style="padding: 0 15px;">
            <div class="col-md-10 col-lg-8 center-block" style="padding: 0;">
                <input type="text" name="name" class="form-field form-control" required="required" placeholder="文件名"/>
            </div>
        </div>
        <div class="form-group row" style="padding: 0 15px;">
            <div class="col-md-10 col-lg-8 center-block" style="padding: 0; border: 1px solid #ccc; border-radius: 4px;">
                <textarea name="text" rows="20" class="form-field form-control invisible"></textarea>
            </div>
        </div>
        <hr/>
        <div class="row">
            <div class="col-md-10 col-lg-8 center-block text-center">
                <button type="submit" class="commit btn btn-primary">保存</button>
                <button type="button" class="cancel btn btn-link"   >取消</button>
            </div>
        </div>
        <br/>
    </form>
</div>
<script type="text/javascript">
    (function($) {
        var context = H$("#manage-file-file-modify");
        var loadbox = context.closest(".loadbox");
        var loadpms = hsSerialArr(loadbox       );
        var path    = hsGetSeria (loadpms,"path");

        context.find("[name='path']").val( path );

        context.data("_fill_text", function(inp, val, n, t) {
            var name = this._info.name;
            var mode = getModeByName(name);
            if (/\.properties$/.test(name)) {
                val  = decodeUnicode(val );
            }

            setTimeout (function() {
                var ch = $(window).height() - 70 - 50 - 96; // 顶部,文件名,底部
                var cm = CodeMirror.fromTextArea(inp[0], {
                    lineNumbers : true,
                    smartIndent : true,
                    indentUnit  : 4,
                    tabSize     : 4,
                    mode        : mode
                });
                cm.setSize(null , ch );
                inp. data ("CM" , cm );
            }, 500);

            return val;
        });

        context.find("[name=name]").on("change", function() {
            var inst = context.find("[name=text]").data("CM");
            if (inst === undefined) return;
            var name = $(this).val( );
            var mode = getModeByName(name);
            inst.setOption( "mode" , mode);
        });

        context.find("form").on("submit", function(evt) {
            var form = $(this);
            var inst = context.data( "HsForm" );
            var path = form.find("[name=path]").val();
            var name = form.find("[name=name]").val();
            var text = form.find("[name=text]").data("CM").getValue();
            var dist = path.replace(/\/[^\/]*$/, '' );
            if (/\.properties$/.test(name)) {
                text = encodeUnicode(text);
            }
            var data = {
                dist : dist + "/" + name,
                path : path,
                text : text,
                type :"file"
            };
            evt.stopPropagation();
            evt.preventDefault( );
            if (!inst.validate()) {
                return false;
            }
            jQuery.hsAjax({
                "url"       : form.attr("action"),
                "data"      : data,
                "type"      : "POST",
                "dataType"  : "json",
                "funcName"  : "save",
                "async"     : false,
                "cache"     : false,
                "global"    : false,
                "context"   : inst,
                "complete"  : inst.saveBack,
                "error"     : function() { return false; }
            });
            return false;
        });
    })(jQuery);
</script>